<template>
    <div>
        <el-form v-if="!switchValue" :inline="true"  :model="userForm" class="demo-form-inline">
            <el-form-item label="人员工号">
                <el-input size="mini" v-model="userForm.empcode" placeholder="人员工号"></el-input>
            </el-form-item>
            <el-form-item label="人员名称">
                <el-input size="mini" v-model="userForm.empname" placeholder="人员名称"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button size="mini" type="primary" @click="queryuser">查询</el-button>
            </el-form-item>
        </el-form>
        <slot>用户列表</slot>
        <el-table
            :data="tableData"
            height="420"
            @row-click="currentUserClick"
            @current-change="currentUserChange"
            style="width: 100%">
            <el-table-column  prop="empcode" label="工号" ></el-table-column>
            <el-table-column prop="empname" label="姓名" ></el-table-column>
            <el-table-column prop="orgname" label="部门"></el-table-column>
        </el-table>
        <el-pagination
            small
            layout="sizes,prev, pager, next,total"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="5"
            @current-change="currentPageChange"
            @size-change="handleSizeChange"
            :total="page.total">
        </el-pagination>
    </div>
</template>
<script>
import request from "../../../../../utils/request.js";
export default {
    data() {
      return {
        userForm: {
            empcode:"",
            empname:""
        },
        page:{
            total:10,
            pageSize:5,
            curPageNum:1
        },
        tableData:[],
        curRoleRow:{},
        curUserRow:{}
      }
    },
    props:{
        switchValue:{
            type:Boolean
        }
    },
    methods:{
        currentPageChange(val){
            this.page.curPageNum = val;
            this.$options.methods.queryuser.bind(this)();
        },
        handleSizeChange(val){
            this.page.pageSize = val;
        },
        currentUserChange(row){
            this.curUserRow = row;
        },
        currentUserClick(){
            if(!this.switchValue){
                //加载角色列表
                this.$bus.$emit("loadRoleList",this.curUserRow);
            }
        },
        queryuser(){
            const that = this;
            if(!this.switchValue){
                var queryData = {"curPageNum":this.page.curPageNum,"pageSize":this.page.pageSize,
                                "empname":this.userForm.empname,"empcode":this.userForm.empcode};
                request.post("/system/query/queryUserDetailPage",queryData).then((res)=>{
                    that.tableData = res.data.list;
                    that.page.total = res.data.total;
                })
            }else{
                request.post("/system/query/queryUserDetailPage",
                    {"inroleid":this.curRoleRow.id,"curPageNum":this.page.curPageNum,"pageSize":this.page.pageSize}).then((res)=>{
                    that.tableData = res.data.list;
                    that.page.total = res.data.total;
                })
            }
            
        }
    },
    mounted(){
        this.$bus.$on("loadUserList",(curRoleRow)=>{
            this.curRoleRow = curRoleRow;
            this.$options.methods.queryuser.bind(this)();
        });
    }
}
</script>